import React, {useEffect} from 'react'
import Axios from 'axios'
import { connect } from 'react-redux'

const PageB= ({age , fn, fn1}) => {
  useEffect(() => {
    Axios.get('/fruits.json').then(res => {
      const {data} = res
      fn1(data)
    })
  }, [fn1])

  return (
    <div>
      <h2>PageB-{age}</h2>
      <button onClick={fn}>点击修改age</button>
    </div>
  )
}

export default connect(
  (state) => {
    return {
      age: state.age
    }
  },

  (dispatch) => {
    return {
      fn () {
        dispatch({
          type: 'CHANGE_AGE', 
          age: 20
        })
      },

      fn1 (list) {
        dispatch({
          type: 'INIT_FRUITS',
          list
        })
      }
    }
  }
)(PageB)